package poolserver

import (
	"crypto/aes"
	"encoding/hex"
)

var aes_key = []byte("zqpool@2024%AesKEY!j5V1lDzsYoryG")

func EncryptAES(plaintext string) (int, string) {
	c, err := aes.NewCipher(aes_key)
	if err != nil {
		return -1, err.Error()
	}

	out := make([]byte, len(plaintext))

	c.Encrypt(out, []byte(plaintext))

	return 0, hex.EncodeToString(out)
}

func DecryptAES(ct string) (int, string) {
	ciphertext, _ := hex.DecodeString(ct)

	c, err := aes.NewCipher(aes_key)
	if err != nil {
		return -1, err.Error()
	}

	pt := make([]byte, len(ciphertext))
	c.Decrypt(pt, ciphertext)

	pw := string(pt[:])
	return 0, pw
}
